package com.itheima.service.impl;

import com.itheima.dao.CheckGroupDao;
import com.itheima.dao.CheckItemDao;
import com.itheima.dao.SetmealDao;
import com.itheima.pojo.CheckGroup;
import com.itheima.pojo.CheckItem;
import com.itheima.pojo.Setmeal;
import com.itheima.service.SetmealService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SetmealServiceImpl implements SetmealService {
    @Autowired
    private SetmealDao setmealDao;
    @Autowired
    private CheckGroupDao checkGroupDao;
    @Autowired
    private CheckItemDao checkItemDao;
    /**
     * 获取所有套餐信息
     * @return
     */
    @Override
    public List<Setmeal> getAllSetmeal() {
        List<Setmeal> setmealList= setmealDao.getAllSetmeal();
        return setmealList;
    }
    /**
     * 根据套餐id查询套餐详情，包含（套餐基本信息、套餐关联的检查组、检查组关联的检查项）
     * @param id
     * @return
     */
    @Override
    public Setmeal findById(String id) {
        Integer setmealId=Integer.parseInt(id);
        //查询套餐数据
        Setmeal setmeal= setmealDao.findById(setmealId);
        //根据套餐id查询检查组数据
        List<CheckGroup> checkGroupList=checkGroupDao.getBySetmealId(setmealId);

        for (CheckGroup checkGroup : checkGroupList) {
            //根据检查组id查询检查项数据
            List<CheckItem> checkItemList=checkItemDao.getByCheckGroupId(checkGroup.getId());
            //赋值到检查组里
            checkGroup.setCheckItems(checkItemList);
        }
        //检查组赋值到套餐里
        setmeal.setCheckGroups(checkGroupList);
        return setmeal;
    }
}
